#ifndef _DVB_H
#define _DVB_H

#define DVB_DEBUG_LEVEL_COMMON	0
#define DVB_DEBUG_LEVEL_ERROR	1
#define DVB_DEBUG_LEVEL_NONE		2

#define DVB_STRING_MAX_LEN 0x100

typedef enum
{
	DVB_GROUP_TV,
	DVB_GROUP_RADIO,
	DVB_GROUP_USER_DEFINE,
}DVB_GROUP_T;


typedef struct
{
	int channel;
	unsigned int frequency;
	int bandwidth;
	int	symbol_rate;
	int	modulation;
	unsigned char	tunertype;
}dvb_frequency_t;


typedef struct 
{
	unsigned short netId;
	unsigned short tsId;
	unsigned short serviceId;
	unsigned int   frequence;//khz
}dvb_service_t;


typedef struct{
	unsigned short 	m_u16ServiceID; 
	unsigned int 		m_u32ServiceType;
	char 			m_as8ServiceName[100];
	unsigned short 	m_u16TsID;
	unsigned short 	m_u16NetID;
	unsigned int 		m_u32Freq;
	unsigned int 		m_u32Sym;
	unsigned int 		m_u32Band;
	unsigned int 		m_u32Mod;
	unsigned int 		m_u32TunerType;
	unsigned int 		m_u32IsDescramble; 
	unsigned int 		m_u32IsLocked; 
	unsigned int 		m_u32IsUsed; 
	unsigned int 		m_u32Volume;
	unsigned int 		m_u32StereoMode;
	unsigned int		m_u32ChannelNumber;
}dvb_service_info_t;

#define	TUNER_T    0
#define	TUNER_C    1
#define	TUNER_S     2

typedef struct
{
	unsigned short 	serviceid;
	unsigned short 	tsid;
	unsigned short 	orgnetid;
	unsigned int		freq;
	unsigned int		sym;
	unsigned int 		mod;
	unsigned int		tunertype;
	char				name[32];
}dvb_networt_service_t;

typedef struct
{
	unsigned short	year;
	unsigned short	month;
	unsigned short	mday;
	unsigned short	wday;
	unsigned char		hour;
	unsigned char		minute;
	unsigned char		second;
}dvb_time_t;

typedef struct
{
	unsigned short	event_id;
	dvb_time_t		StartTime;
	dvb_time_t		EndTime;
	unsigned int		duration;
	unsigned char		lang[4];
	char				EventName[256];	
	char				Desc[512];	
	char				ExtendDesc[1024];
	unsigned short	running_status;
}dvb_event_t;


typedef enum
{
	SEARCH_START,		
	SEARCH_TUNER_LOCK,	
	SEARCH_IN_PROCESS,
	SEARCH_FINISH,	
	SEARCH_END,
	NETWORK_UPDATE,
	SCAN_FINISH,
	DVB_INIT_FINISH,
	SCAN_IN_PROCESS,
	SCAN_START,
}SEARCH_PROCESS;

typedef void (*pSearchCallback)(unsigned int , unsigned char, void*);

typedef struct
{
	char			szName[100];
	unsigned char	serviceType;
	unsigned char bEncrypt;
	unsigned short serviceId;
	unsigned short lcn;
}search_service_info_t;

typedef struct
{
	char			m_s8NetName[DVB_STRING_MAX_LEN];
	unsigned int	m_u32NetID;
}dvb_operator_info_t;

typedef enum
{
	DVB_CB_TYPE_CI = 1,
	DVB_CB_TYPE_EPG = 2,
	DVB_CB_TYPE_SCAN = 3,
	DVB_CB_TYPE_SERVICE = 4,
	DVB_CB_TYPE_SETUP = 5,
	DVB_CB_TYPE_SYSTEM = 6,
	DVB_CB_TYPE_UPDATE = 7,
}DVB_CB_TYPE_T;

typedef enum
{
	MSG_UPDATE_REQUEST_FIRMWARE=701,
	MSG_UPDATE_NO_NEED_UPDATE=702,
	MSG_UPDATE_START=703,
	MSG_UPDATE_PROGRESS=704,
	MSG_UPDATE_FINISH = 705,
	MSG_UPDATE_SUCCESS = 706,
	MSG_UPDATE_ERROR=707,
}SDK_DONGLE_FIRMWARE;


typedef enum
{
	MSG_CI_DATA_UPDATED = 101,
	MSG_CI_SHOW_MMI_MENU = 102,
	MSG_CI_UPDATE_MMI_MENU = 103,
	MSG_CI_HIDE_MMI_MENU = 104,
	MSG_CI_SHOW_PIN_DIALOG = 105,
	MSG_CI_HIDE_PIN_DIALOG = 106,
}DVB_MSG_CI_DATA_TYPE_T;

typedef enum
{
	MSG_SCAN_ERROR = 301,
	MSG_SCAN_START = 302,		//dvb_tuner_t
	MSG_SCAN_DVB_NETWORK = 303,//dvb_network_t
	MSG_SCAN_TUNER_LOCKED = 304,		//dvb_tuner_status_t
	MSG_SCAN_PROGRESS_CHANGED = 305,	//dvb_process_t
	MSG_SCAN_SERVICES_FOUND = 306,		//builder_scan_services_t;
	MSG_SCAN_FINISH = 307,				
}DVB_MSG_SCAN_TYPE_T;

typedef enum
{
	MSG_SERVICE_HAS_TS = 401,
	MSG_SERVICE_FREE_AND_RESET_PLAYER = 402,
	MSG_SERVICE_FREE_WITHOUT_RESET_PLAYER = 403,
	MSG_SERVICE_SCRAMBLED = 404,
	MSG_SERVICE_TS_PLAYER_PREPARED = 405,
	MSG_SERVICE_SIGNAL_BAD = 406,
	MSG_SERVICE_SIGNAL_GOOD = 407,
	MSG_SERVICE_STOPPED = 408,
}DVB_MSG_SERVICE_TYPE_T;

typedef enum
{
	MSG_SYSTEM_ERROR = 601,
	MSG_SYSTEM_INITIALIZE = 602,
	MSG_SYSTEM_RESUME = 603,
	MSG_SYSTEM_STANDBY = 604,
	MSG_SYSTEM_TERMINATE = 605,
	MSG_SYSTEM_INIT_OK = 606,
}DVB_MSG_SYSTEM_TYPE_T;


typedef struct
{
	char m_as8NetworkName[32];
	unsigned int m_u32NetworkID;
}dvb_network_t;

typedef struct
{
	unsigned int m_u32Process;
}dvb_process_t;

typedef struct
{
	char				m_s8Name[100];
	unsigned char		m_u8ServiceType;
	unsigned char 	m_u8Encrypt;
	unsigned short 	m_u16ServiceId;
}builder_scan_service_t;

typedef struct
{
	unsigned int				m_u32Cnt;
	builder_scan_service_t* 	m_pstServices;
}builder_scan_services_t;

typedef int (*pfDVBCallback)(DVB_CB_TYPE_T eType, int msg, void* param);


typedef void (*pfDvbDebug)(unsigned int u32Level, const char*);

extern void DVBRegistorDebugFun(pfDvbDebug);


int DVBSetServiceGroupId(unsigned int u32GroupId);

int DVBGetServiceGroupId(unsigned int* pu32GroupId);

int DVBRestoreSettings();

dvb_time_t DVBGetDVBTime();

int DVBGetAllServices(dvb_service_info_t* pstServices, unsigned int* pu32Cnt);

int DVBManualTune(dvb_tuner_t* pstTunerInfo);

void DVBStartImportServices();

int DVBImportServices(dvb_networt_service_t* pstProgramList, unsigned int u32Num, unsigned int u32GroupIndex, const char* ps8GroupName);

void DVBFinishImportServices();

int DVBManualScan(dvb_tuner_t* stTunerInfo);

int DVBAutoScan( int startFreq, int endFreq);

int DVBFullScan( int startFreq, int endFreq);

int DVBAbortScan();

int DVBPlayServiceByIndex( int index);

int DVBGetEitInfo(dvb_service_t* pstService, int type, dvb_event_t* pstEvent);

int DVBGetScheduleInfo(dvb_service_t* pstService, dvb_event_t* pstEventList, unsigned int* pu32Cnt);

int DVBSetFrequencyTable(dvb_frequency_t* pstFreqTable, unsigned int u32Num);

int DVBSetDVBPluginPath(const char* ps8Path);

void DVBStopDVBService();

void DVBStandby();

void DVBResume();

void DVBRegistorDebugFun(pfDvbDebug pfDvbDebugFun);

int DVBInitialize();

int DVBTerminate();

int DVBRegistorCallback(pfDVBCallback pfCb);

int DVBDeviceStatusChanged(unsigned char status, int fd);

int DmxCallBack(unsigned long filterId,  unsigned char* pu8Data,unsigned short u16Datalen);

#endif//_DVB_H
